import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  UseGuards,
} from '@nestjs/common';
import { SmtpService } from './smtp.service';
import { CreateSmtpDto } from './dto/create-smtp.dto';
import { UpdateSmtpDto } from './dto/update-smtp.dto';
import { findSmtpDto } from './dto/find-smtp.dto';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { Roles, RolesGuard } from '../auth/role.guard';

@ApiTags('邮件')
@Controller('smtp')
export class SmtpController {
  constructor(private readonly smtpService: SmtpService) {}

  @ApiOperation({ summary: '发送邮件' })
  @ApiBearerAuth()
  @Roles('admin', 'root')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  @Post()
  create(@Body() createSmtpDto: CreateSmtpDto) {
    return this.smtpService.create(createSmtpDto);
  }

  @ApiOperation({ summary: '查看发送邮件记录' })
  @ApiBearerAuth()
  @Roles('admin', 'root')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  @Get()
  findAll(@Query() query: findSmtpDto) {
    return this.smtpService.findAll(query);
  }

  @ApiOperation({ summary: '查看单个发送邮件记录' })
  @ApiBearerAuth()
  @Roles('admin', 'root')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.smtpService.findOne(id);
  }

  @ApiOperation({ summary: '修改发送邮件记录' })
  @ApiBearerAuth()
  @Roles('admin', 'root')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  @Patch(':id')
  update(@Param('id') id: number, @Body() updateSmtpDto: UpdateSmtpDto) {
    return this.smtpService.update(id, updateSmtpDto);
  }

  @ApiOperation({ summary: '删除发送邮件记录' })
  @ApiBearerAuth()
  @Roles('admin', 'root')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  @Delete(':id')
  remove(@Param('id') id: number) {
    return this.smtpService.remove(id);
  }
}
